package com.example.demo5;

import android.icu.util.Calendar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.Toast;

public class demo5MainActivity extends AppCompatActivity {


    private int year,month,day;
    private DatePicker datePicker;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo5_main);

        datePicker = (DatePicker)findViewById(R.id.datepicker);
        Calendar calendar = Calendar.getInstance();
//        year = datePicker.getYear();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH);
        day = calendar.get(Calendar.DAY_OF_MONTH);

        datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                demo5MainActivity.this.year=year;
                demo5MainActivity.this.month=monthOfYear;
                demo5MainActivity.this.day=dayOfMonth;
                show(year,monthOfYear,dayOfMonth);
            }
        });
    }
    private void show(int year,int mouth,int day){
        String str = year+"年"+(mouth+1)+"月"+day+"日";
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();

    }
}
